package com.controller;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.controller.base.BaseController;
import com.entity.FuJianGuanXi;
import com.entity.YongHu;
import com.service.FjgxService;
import com.service.UserService;
import com.util.Md5;

@Controller
@RequestMapping("/yonghu/manager")
public class UserController extends BaseController<YongHu>{
		@Autowired
		private UserService yhService;
		@Autowired
		private FjgxService fjgxService;
		
		@RequestMapping("/adduser")
		@ResponseBody
		public AjaxRes adduser(YongHu yh,String fujianId){
			AjaxRes res = new AjaxRes();
			try {
				yhService.insertFj(yh,fujianId);
				res.setResMsg("添加成功");
			} catch (Exception e) {
				System.out.println("ER:"+e.getMessage());
				res.setResMsg("添加失败");
			}
			return res;	
			
		}
		
		@RequestMapping("/findByPage")
		@ResponseBody
		public AjaxRes findByPage(YongHu yh,Page<YongHu> page){
			AjaxRes res = new AjaxRes();
			System.out.println(yh.getId());
			page = yhService.findByPage(yh, page);
			res.setSucceed(page,"成功");
			return res;
		}
		@RequestMapping("/delyh")
		@ResponseBody
		public AjaxRes delyhhy(YongHu yh){
			AjaxRes res = new AjaxRes();
			yhService.delete(yh);
			res.setSucceedMsg("删除成功");
			return res;
		}
		
		@RequestMapping("/delAllyh")
		@ResponseBody
		public AjaxRes delAllyhhy(String cks){
			AjaxRes res = new AjaxRes(); 
			String[] ck = cks.split(",");
			List<YongHu> list = new ArrayList<YongHu>();
			for(String s:ck){
				YongHu yh = new YongHu();
				yh.setId(s);
				list.add(yh);
			}
			yhService.deleteBatch(list);
			res.setSucceedMsg("删除成功");
			return res;
		}

		
		@RequestMapping("/updateyh")
		@ResponseBody
		public AjaxRes updateyhhy(YongHu yh){
			AjaxRes res = new AjaxRes();
			yhService.update(yh);
			res.setSucceedMsg("修改成功");
			return res;
		}
		@RequestMapping("/findByFujian")
		@ResponseBody
		public AjaxRes findByFujian(FuJianGuanXi o){
			AjaxRes res = new AjaxRes();
			List<FuJianGuanXi> fjgxList = fjgxService.findByFujian(o);
			res.setSucceed(fjgxList,"获取数据成功");
			return res;
		}



}

